package com.smyhvae.viewpagerdemo.viewpager;

import android.support.v4.view.ViewPager;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.ImageView;
import com.smyhvae.viewpagerdemo.R;
import com.smyhvae.viewpagerdemo.viewpager.viewpager.MyPageTransformer;
import com.smyhvae.viewpagerdemo.viewpager.viewpager.ViewPagerAdapter;
import java.util.ArrayList;
import java.util.List;

public class MainActivity extends AppCompatActivity {

    private ViewPager mViewPager;
    private ViewPagerAdapter viewPagerAdapter;
    private List<View> mViewList;
    private ImageView imageView;
    private Integer[] imageIds = {R.drawable.len, R.drawable.leo, R.drawable.lep,
            R.drawable.ler, R.drawable.les};

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        initView();
        mViewPager = (ViewPager) findViewById(R.id.view_pager);
        viewPagerAdapter = new ViewPagerAdapter(mViewList);
        mViewPager.setAdapter(viewPagerAdapter);
        mViewPager.setPageTransformer(true, new MyPageTransformer());
    }

    private void initView(){
        mViewList = new ArrayList<>();
        for (int i = 0; i < imageIds.length; i++){
            View view = LayoutInflater.from(this).inflate(R.layout.view_pager_item, null);
            imageView = (ImageView) view.findViewById(R.id.image_view);
            imageView.setImageResource(imageIds[i]);
            mViewList.add(view);
        }
    }
}
